c program to read and write to a file